//
//  YCShopSearchViewController.m
//  YCSchool
//
//  Created by gmall on 16/5/13.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//  商家搜索

#import "YCShopSearchViewController.h"
#import "YCShopFindViewController.h"
#import "YCShopListCell.h"


#pragma mark - 
#pragma mark - YCShopSearchViewController

@interface YCShopSearchViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UIView *firstView;
/** 搜索条  */
@property (nonatomic, strong) UIButton *searchButton;
/** 商家推荐label  */
@property (nonatomic, strong) UILabel *shopRecommendLabel;
@property (nonatomic, strong) UITableView *tableView;

@end

@implementation YCShopSearchViewController

#pragma mark - 属性获取方法

- (UIView *)firstView
{
    if (!_firstView)
    {
        _firstView = [[UIView alloc] init];
        _firstView.backgroundColor = [UIColor whiteColor];
    }
    
    return _firstView;
}
// 搜索条
- (UIButton *)searchButton
{
    if (!_searchButton)
    {
        _searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_searchButton setTitle:@"输入商家 关键词" forState:UIControlStateNormal];
        [_searchButton setTitleColor:[UIColor yc_colorWithUInt:0x8c8c8c] forState:UIControlStateNormal];
        _searchButton.backgroundColor = [UIColor yc_colorWithUInt:0xeaebed];
        _searchButton.layer.cornerRadius = 5;
        _searchButton.layer.masksToBounds = YES;
        _searchButton.titleLabel.font = [UIFont systemFontOfSize:13];
        [_searchButton setImage:[UIImage imageNamed:@"search_friends"] forState:UIControlStateNormal];
        _searchButton.imageView.contentMode = UIViewContentModeCenter;
        [_searchButton addTarget:self action:@selector(didTouchUpInsideSearchShopButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _searchButton;
}

- (UILabel *)shopRecommendLabel
{
    if (!_shopRecommendLabel) {
        _shopRecommendLabel = [[UILabel alloc] init];
        _shopRecommendLabel.text = @"商家推荐";
        _shopRecommendLabel.textColor = [UIColor redColor];
        _shopRecommendLabel.font = [UIFont systemFontOfSize:15];
    }
    return _shopRecommendLabel;
}

- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 87;//80;
        
        _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 0.3)];
        _tableView.tableFooterView.backgroundColor = [UIColor clearColor];
    }
    
    return _tableView;
}

#pragma mark - 生命周期

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self yc_addBackBarButtonItem];
    self.navigationItem.title = @"商家搜索";
    
    [self.view addSubview:self.firstView];
    [self.firstView addSubview:self.searchButton];
    [self.view addSubview:self.shopRecommendLabel];
    [self.view addSubview:self.tableView];
    [self layout];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)layout
{
    [self.firstView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@150);
        make.left.top.right.equalTo(self.view);
    }];

    [self.searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.firstView);
        make.left.equalTo(self.firstView).offset(26);
        make.right.equalTo(self.firstView).offset(-26);
        make.height.equalTo(@40);
    }];
    
    [self.shopRecommendLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(26);
        make.top.equalTo(self.firstView.mas_bottom);
    }];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.shopRecommendLabel.mas_bottom);
        make.left.bottom.right.equalTo(self.view);
    }];
}


#pragma mark - UITableView delegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;//self.searchArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *iden = @"IDEN";
    
    YCShopListCell *cell = [tableView dequeueReusableCellWithIdentifier:iden];
    if (!cell)
    {
        cell = [[YCShopListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iden];
    }
    
    //    GOCustomerUser *user = self.searchArray[indexPath.row];
    
    [cell.headerImageView yc_setWebImageWithURLString:@"" holderSize:CGSizeMake(57, 57)];
    cell.nameLabel.text = @"张行";
    cell.attentionLabel.text = @"关注人数 900";
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    //    GOCustomerUser *user = self.searchArray[indexPath.row];
    //    GOShowOffModel *model = [[GOShowOffModel alloc] init];
    //    model.userId = user.cuUserId;
    //    GOOstentatiousForOtherViewController *vc = [[GOOstentatiousForOtherViewController alloc] initWithModel:model];
    //    [self.navigationController pushViewController:vc animated:YES];
}


#pragma mark - 点击事件

// 点击搜索条
- (void)didTouchUpInsideSearchShopButton:(UIButton *)button
{
    YCLogFunc
    YCShopFindViewController *shopFindVc = [[YCShopFindViewController alloc] init];
    [self.navigationController pushViewController:shopFindVc animated:YES];
}




@end
